<%@page import="util.TextFormat"%>
<%@page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%@page import="java.util.List"%>
<%@page import="entity.Cart"%>
<%@page import="entity.CartItem"%>
<%@page import="entity.Product"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	Cart cart = (Cart)session.getAttribute("cart");
	List<CartItem> items = cart.list();
%>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>当当图书 – 全球最大的中文网上书店</title>
		<link href="<%=request.getContextPath()%>/css/book.css" rel="stylesheet" type="text/css" />
		<link href="<%=request.getContextPath()%>/css/second.css" rel="stylesheet" type="text/css" />
		<link href="<%=request.getContextPath()%>/css/secBook_Show.css" rel="stylesheet" type="text/css" />
		<link href="<%=request.getContextPath()%>/css/shopping_vehicle.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.3.js"></script>
		<script type="text/javascript">
			function updateCart(id){
				var count = parseInt(jQuery.trim(jQuery("#count_" + id).html()));
				if (count == 2147483647) {
					num = 0;
				} else {
					var num = jQuery("#numinput_" + id).val();
					if (jQuery.trim(num) == "") {
						jQuery("#numinput_" + id).val("");
						alert("请填写数量");
						return;
					}
					if(isNaN(num)){
						num = 1;
					} else {
						num = parseInt(num);
						if((num <= 0) || (num + count > 2147483647)){
							num = 1;
						}
					}
				}
				jQuery("#numinput_" + id).val(num);
				window.location.href = "<%=request.getContextPath()%>/cart/update.do?id=" + id + "&count=" + num;
			}
			
			function settlement(s){
				if (s == 0) {
					alert("还没有购买商品");
					return;
				}
				window.location.href = "<%=request.getContextPath()%>/order/orderInfo.do";
			}
		</script>
	</head>
	<body>
		<br/>
		<br/>
		<div class="my_shopping">
			<img class="pic_shop" src="<%=request.getContextPath()%>/images/pic_myshopping.gif" />
		</div>
		
		<div id="div_choice" class="choice_merch">
			<h2 id="cart_tips">
				您已选购以下商品
			</h2>
			<div class="choice_bord">
				<table class="tabl_buy" id="tbCartItemsNormal">
					<tr class="tabl_buy_title">
						<td class="buy_td_6">
							<span>&nbsp;</span>
						</td>
						<td>
							<span class="span_w1">商品名</span>
						</td>
						<td class="buy_td_5">
							<span class="span_w2">市场价</span>
						</td>
						<td class="buy_td_4">
							<span class="span_w3">当当价</span>
						</td>
						<td class="buy_td_1">
							<span class="span_w2">数量</span>
						</td>
						<td class="buy_td_2">
							<span>变更数量</span>
						</td>
						<td class="buy_td_1">
							<span>删除</span>
						</td>
					</tr>
					<tr class='objhide' >
						<td colspan="8">
							&nbsp;
						</td>
					</tr>
				<%
					for(int i = 0; i < items.size(); i++){
						CartItem item = items.get(i);
						Product product = item.getProduct();
						if(product.getHas_deleted().intValue() == 0){
				%>
					<!-- 购物列表开始 -->
						<tr class='td_no_bord'>
							<td style='display: none'>
							</td>
							<td class="buy_td_6">
								<span class="objhide"><img/></span>
							</td>
							<td>
								<a href="javascript:;"><%=product.getProduct_name()%></a>
							</td>
							<td class="buy_td_5">
								<span class="c_gray">￥<%=TextFormat.formatNumber(product.getFixed_price())%></span>
							</td>
							<td class="buy_td_4">
								&nbsp;&nbsp;
								<span>￥<%=TextFormat.formatNumber(product.getDang_price())%></span>
							</td>
							<td class="buy_td_1" id="count_<%=product.getId()%>">
								&nbsp;&nbsp;<%=item.getCount()%>
							</td>

							<td >
								<input class="del_num" type="text" size="3" maxlength="4" id='numinput_<%=product.getId()%>'/>
								<a href="javascript:;" onclick="updateCart(<%=product.getId()%>);">变更</a>
							</td>
							<td>
								<a href="<%=request.getContextPath()%>/cart/delete.do?id=<%=product.getId()%>" >删除</a>
							</td>
						</tr>
					<!-- 购物列表结束 -->
				<%
						}
					}
				%>
                      
				</table>
					<%
						if(items.size() == 0){
					%>
						<div id="choice_bord">
							您还没有挑选商品
						</div>
					<%
						}
					%>
					
				<div class="choice_balance">
					<div class="select_merch">
						<a href='<%=request.getContextPath()%>/main/toMain.do'> 继续挑选商品&gt;&gt;</a>
					</div>
						<div class="total_balance">
							<div class="save_total">
								您共节省：
								<span class="c_red"> ￥<span id="total_economy"><%=TextFormat.formatNumber(cart.getSaveMoney())%></span>
								</span>
								<span id='total_vip_economy' class='objhide'> 
									( 其中享有优惠： <span class="c_red"> ￥<span id='span_vip_economy'></span></span>) 
								</span>
								<span style="font-size: 14px">|</span>
								<span class="t_add">商品金额总计：</span>
								<span class="c_red_b"> ￥<span id='total_account'><%=TextFormat.formatNumber(cart.getTotalPrice())%></span>
								</span>
							</div>
							<div id="balance" class="balance">
								<a name='checkout' href='javascript:;' onclick="settlement(<%=items.size()%>);">
									<img src="<%=request.getContextPath()%>/images/butt_balance.gif" alt="结算" border="0" title="结算" />
								</a>
							</div>
						</div>
				</div>
			</div>
		</div>

		<!-- 用户删除恢复区 -->
		<div id="divCartItemsRemoved" class="del_merch">
			<div class="del_title">
				您已删除以下商品，如果想重新购买，请点击“恢复”
				<div style="float: right; margin-right: 10px;">
				[<a href="<%=request.getContextPath()%>/cart/cleardeleted.do">清空</a>]
				</div>
			</div>
						
			<table class="tabl_del" id="del_table">
				<tbody>
				<%
					for(int i = 0; i <items.size(); i++){
						CartItem item = items.get(i);
						Product product = item.getProduct();
						if(product.getHas_deleted().intValue() == 1){
				%>
					<tr>
						<td width="58" class="buy_td_6">
							&nbsp;
						</td>
						<td width="365" class="t2">
							<a href="javascript:;"><%=product.getProduct_name()%></a>
						</td>
						<td width="106" class="buy_td_5">
							￥<%=TextFormat.formatNumber(product.getFixed_price())%>
						</td>
						<td width="134" class="buy_td_4">
							<span>￥<%=TextFormat.formatNumber(product.getDang_price())%></span>
						</td>
						<td width="56" class="buy_td_1">
							<a href="<%=request.getContextPath()%>/cart/rebuy.do?id=<%=product.getId()%>">恢复</a>
						</td>
						<td width="16" class="objhide">
							&nbsp;
						</td>
					</tr>
				<%
						}
					}
				%>
					<tr class="td_add_bord">
						<td colspan="8">
							&nbsp;
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br />
		<br />
		<br />
		<br />
		<!--页尾开始 -->
		<%@include file="../common/foot.jsp"%>
		<!--页尾结束 -->
	</body>
</html>



